/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.latticeware.xtalk.app;

import com.latticeware.xtalk.stack.Button;
import com.latticeware.xtalk.stack.Card;
import com.latticeware.xtalk.stack.Field;
import java.util.HashMap;
import java.util.Map;



/**
 *
 * @author sfisque
 */
public class ObjectFactory
{
    private static ObjectFactory instance;
    
    private Integer cardIDX;
    
    private Integer buttonIDX;
    
    private Integer fieldIDX;
    
    
    private Map<Integer, Card> cardMap;
    
    private Map<Integer, Button> buttonMap;
    
    private Map<Integer, Field> fieldMap;
    
    
    private ObjectFactory()
    {
        buttonIDX = 1;
        cardIDX = 1;
        fieldIDX = 1;
        
        cardMap = new HashMap<Integer, Card>( 17 );
        buttonMap = new HashMap<Integer, Button>( 17 );
        fieldMap = new HashMap<Integer, Field>( 17 );
    }
    
    
    public static ObjectFactory getInstance()
    {
        if( instance == null )
        {
            instance = new ObjectFactory();
        }
        
        return instance;
    }
    
    
    public Integer getButtonId()
    {
        return buttonIDX ++;
    }
    
    public Integer getCardId()
    {
        return cardIDX ++;
    }
    
    public Integer getFieldId()
    {
        return fieldIDX ++;
    }
    
    public Button newButton()
    {
        Button _button = new Button( getButtonId() );
        
        buttonMap.put( _button.getId(), _button );
        
        return _button;
    }
    
    
    public Card newCard()
    {
        Card _card = new Card( getCardId() );
        
        cardMap.put( _card.getId(), _card );
        
        return _card;
    }
    
    
    public Field newField()
    {
        Field _field = new Field( getFieldId() );
        
        fieldMap.put( _field.getId(), _field );
        
        return _field;
    }
}
